package com.netflexitysolutions.amazonws.s3.internal.operations;

import java.util.List;

import com.amazonaws.s3.doc._2006_03_01.SetBucketAccessControlPolicy;
import com.amazonaws.s3.doc._2006_03_01.SetBucketAccessControlPolicyResponse;
import com.netflexitysolutions.amazonws.s3.S3;
import com.netflexitysolutions.amazonws.s3.S3Grant;
import com.netflexitysolutions.amazonws.s3.S3ServerResponseStatus;
import com.netflexitysolutions.amazonws.s3.internal.utils.S3Utils;

public class SetBucketAccessControlPolicyOperation extends OperationExecutor<SetBucketAccessControlPolicy, S3ServerResponseStatus>{

    private String bucket;
    private List<S3Grant> acl;

    public SetBucketAccessControlPolicyOperation(S3 s3, String bucket, List<S3Grant> acl){
        super(s3);
        this.bucket = bucket;
        this.acl = acl;
    }

    @Override
    protected S3ServerResponseStatus call(SetBucketAccessControlPolicy request) {
        request.setBucket(bucket);
        request.setAccessControlList(S3Utils.convert(acl));
        injectCredentials(request, "SetBucketAccessControlPolicy", getS3().getAccessKey(), getS3().getSecretKey());
        SetBucketAccessControlPolicyResponse response = getS3().getService().setBucketAccessControlPolicy(request);
//TODO: make test to see what`s happen in real world
//Amazon S3 documentation mismatch: expected SetBucketAccessControlPolicyResponse with Status within
//received GetBucketAccessControlPolicyResponse?
        return new S3ServerResponseStatus(200, "OK");
    }

}
